package br.com.bikerz.user.bike.view;

import br.com.bikerz.user.bike.domain.UserBike;
import java.util.logging.Level;
import br.com.bikerz.user.bike.service.UserBikeService;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import java.util.logging.Logger;
import javax.faces.model.SelectItem;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component("createUserBike")
@Scope("request")
public class CreateUserBike implements Serializable{

        private final static Logger logger = Logger.getLogger(CreateUserBike.class.getName());

	private UserBike userBike = new UserBike();

	private UserBikeService userBikeService;
        private String selectType  = null;
        private String selectModel = null;

	public CreateUserBike() {}

	@Autowired
	public CreateUserBike(UserBikeService userBikeService) {
		this.userBikeService = userBikeService;
	}

	public UserBike getUserBike() {
		return userBike;
	}

	public void setUserBike(UserBike userBike) {
		this.userBike = userBike;
	}

        public List<SelectItem> getTypeOptions(){
                 List<SelectItem> temp = new ArrayList<SelectItem>();
                 temp.add(new SelectItem(1,"Honda"));
                 temp.add(new SelectItem(2,"Yamaha"));
                 temp.add(new SelectItem(3,"Suzuki"));
                 return temp;
        }

        public List<SelectItem> getModelOptions(){
                 List<SelectItem> temp = new ArrayList<SelectItem>();
                 temp.add(new SelectItem(1,"Shadow"));
                 temp.add(new SelectItem(2,"Drag"));
                 temp.add(new SelectItem(3,"Falcon"));
                 return temp;
        }

	public void save(ActionEvent actionEvent) {
                logger.log(Level.INFO, "Marca: " + selectType);

		userBikeService.createNew(userBike);
		FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_INFO, "Info", "UserBike is saved");
		FacesContext.getCurrentInstance().addMessage(null, facesMessage);
		userBike = new UserBike();
	}

        public String getSelectModel() {
            return selectModel;
        }

        public void setSelectModel(String selectModel) {
            this.selectModel = selectModel;
        }

        public String getSelectType() {
            return selectType;
        }

        public void setSelectType(String selectType) {
            this.selectType = selectType;
        } 
}